/**
 * @filename:${entityName}Controller ${createTime}
 * @project ${project}  ${version}
 */
package ${bsControllerUrl};

import com.starhub.common.bean.ID;
import ${entityUrl}.${entityName};
import ${serviceUrl}.${entityName}Service;
import com.starhub.common.bean.ResultResp;
import com.starhub.common.exception.AppException;
import com.starhub.utils.Util;
import com.starhub.engine.security.utils.SecurityUtils;
import com.starhub.engine.sys.user.bean.LoginUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import jakarta.servlet.http.HttpServletRequest;
import java.util.Map;
/**   
 * <p>说明： ${entityComment}API接口层</P>
 * @version: ${version}
 * @author: ${author}
 * @time    ${createTime}
 *
 */
 <#if isSwagger=="true" >
@Api(value="${entityComment}后台接口", tags = {"${entityComment}后台接口"},description = "编写者:${authorName}" )
</#if>
@RestController
@RequestMapping("/engine/starhub/${entityNameLower}")
public class ${entityName}ConfigController {

    @Autowired
    private ${entityName}Service ${entityNameLower}Service;
    /**
    * 日志
    */
    private static final Logger log = LoggerFactory.getLogger(${entityName}ConfigController.class);

    /**
    * ${entityComment}新增
    */
    @ApiOperation(value = "${entityComment}新增", notes = "${entityComment}新增")
    @PostMapping("/add")
    public ResultResp add(@RequestBody ${entityName} ${entityNameLower}){
        ResultResp ResultResp = null;
        try {
            LoginUser user = SecurityUtils.getCurrentUser();
            ResultResp = ResultResp.success(${entityNameLower}Service.add(user, ${entityNameLower}).toString());
        }catch (Exception e){
            log.error(ExceptionUtils.getStackTrace(e));
            ResultResp = ResultResp.fail("接口异常："+e.getMessage(),e);
        }
        return ResultResp;
    }

    /**
    * ${entityComment}修改
    */
    @ApiOperation(value = "${entityComment}修改", notes = "${entityComment}修改")
    @PostMapping("/update")
    public ResultResp update(@RequestBody ${entityName} ${entityNameLower}){
        ResultResp ResultResp = null;
        try {
            LoginUser user = SecurityUtils.getCurrentUser();
            ResultResp = ResultResp.success(${entityNameLower}Service.update(user, ${entityNameLower}));
        }catch (Exception e){
            log.error(ExceptionUtils.getStackTrace(e));
            ResultResp = ResultResp.fail("接口异常："+e.getMessage(),e);
        }
        return ResultResp;
    }

    /**
    * ${entityComment}信息获取
    */
    @ApiOperation(value = "${entityComment}信息获取", notes = "${entityComment}信息获取")
    @GetMapping("/getInfo/{id}")
    public ResultResp getInfo(@PathVariable Long id){
        ResultResp ResultResp = null;
        try {
            LoginUser user = SecurityUtils.getCurrentUser();
            ResultResp = ResultResp.success(${entityNameLower}Service.getInfo(user, id));
        }catch (Exception e){
            log.error(ExceptionUtils.getStackTrace(e));
            ResultResp = ResultResp.fail("接口异常："+e.getMessage(),e);
        }
        return ResultResp;
    }

    /**
    * ${entityComment}逻辑删除
    */
    @ApiOperation(value = "${entityComment}逻辑删除", notes = "${entityComment}逻辑删除")
    @PostMapping("/delete")
    public ResultResp deleteByType(@RequestBody ID id){
        ResultResp ResultResp = null;
        try {
            LoginUser user = SecurityUtils.getCurrentUser();
            ${entityNameLower}Service.deleteByType(user, id.getIds(), 1);
            ResultResp = ResultResp.success("删除成功");
        }catch (Exception e){
            log.error(ExceptionUtils.getStackTrace(e));
            ResultResp = ResultResp.fail("接口异常："+e.getMessage(),e);
        }
        return ResultResp;
    }


    /**
    * ${entityComment}物理删除
    */
    @ApiOperation(value = "${entityComment}物理删除", notes = "${entityComment}物理删除")
    @PostMapping("/deleteRecord")
    public ResultResp deleteRecord(@RequestBody ID id){
        ResultResp ResultResp = null;
        try {
            LoginUser user = SecurityUtils.getCurrentUser();
            ${entityNameLower}Service.deleteRecord(user, id.getIds());
            ResultResp = ResultResp.success("删除成功");
        }catch (Exception e){
            log.error(ExceptionUtils.getStackTrace(e));
            ResultResp = ResultResp.fail("接口异常："+e.getMessage(),e);
        }
        return ResultResp;
    }

    /**
    * ${entityComment}列表获取
    */
    @ApiOperation(value = "${entityComment}列表获取", notes = "${entityComment}列表获取")
    @GetMapping("/getList")
    public ResultResp getList(HttpServletRequest request){
        ResultResp ResultResp = null;
        try {
            LoginUser user = SecurityUtils.getCurrentUser();
            Map<String , Object> params = Util.request2Map(request);
            ResultResp = ResultResp.success( ${entityNameLower}Service.getList(user, params));
        }catch (Exception e){
            log.error(ExceptionUtils.getStackTrace(e));
            ResultResp = ResultResp.fail("接口异常："+e.getMessage(),e);
        }
        return ResultResp;
    }

}